using Firestarter.Test.Base;
using FireStarterModeller.BO;
using Habanero.Base;
using Habanero.BO;
using NUnit.Framework;

namespace FireStarterModeller.Test.BO
{
    /// <summary>
    /// Provides a place to write custom tests for DMClass objects.
    /// This file is only written once and can be changed.  The Def file
    /// attached to this as a dependent is rewritten with each regeneration
    /// and contains the standard tests for DMClass.
    /// Regenerate this test project whenever there have been changes to the
    /// business objects.
    /// If tests are failing due to a unique setup in your application,
    /// you can either override the Create methods in TestUtils, or you
    /// can add the test to the ignore list below and reimplement it here.
    /// </summary>
    [TestFixture]
    public class TestDMClassNameNotEqualToAssemblyName
    {
        [SetUp]
        public void SetupTest()
        {
            //Runs every time that any testmethod is executed
            TestUtilsDomain.SetupTest();
            BORegistry.DataAccessor = new DataAccessorInMemory();
        }

        [TestFixtureSetUp]
        public void TestFixtureSetup()
        {
            //Code that is executed before any test is run in this class. If multiple tests
            // are executed then it will still only be called once.
            TestUtilsDomain.SetupFixture();
        }

        [TearDown]
        public void TearDownTest()
        {
            //runs every time any testmethod is complete
        }

        #region DMClassNameNotEqualToAssemblyName

        [Test]
        public void Test_Construct_ShouldConstructWithCorrectNameAndErrorLevel()
        {
            //---------------Set up test pack-------------------
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IBusinessObjectRule rule = new DMClassNameNotEqualToAssemblyName();
            //---------------Test Result -----------------------
            Assert.IsNotNull(rule);
            Assert.AreEqual("DMClassNameNotEqualToAssemblyName", rule.Name);
            Assert.AreEqual(ErrorLevel.Error, rule.ErrorLevel);
        }


        [Test]
        public void Test_IsValid_False_WhenSameNameAsAssembly()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedValidDMClass();
            dmClass.Assembly.AssemblyName = dmClass.ClassNameBO;
            IBusinessObjectRule rule = new DMClassNameNotEqualToAssemblyName();
            //---------------Assert Precondition----------------
            Assert.AreEqual(dmClass.ClassNameBO, dmClass.AssemblyName);
            //---------------Execute Test ----------------------
            bool isValid = rule.IsValid(dmClass);
            //---------------Test Result -----------------------
            Assert.IsFalse(isValid);
            StringAssert.Contains("The Entity/Class '", rule.Message);
            StringAssert.Contains("'" + dmClass.ToString() + "'", rule.Message);
            StringAssert.Contains("' cannot have the same name as its Assembly/Namespace '", rule.Message);
        }

        [Test]
        public void Test_IsValid_True_WhenNamesAreNotEqual()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedValidDMClass();
            IBusinessObjectRule rule = new DMClassNameNotEqualToAssemblyName();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(dmClass.Assembly);
            Assert.AreNotEqual(dmClass.ClassNameBO, dmClass.AssemblyName);
            //---------------Execute Test ----------------------
            bool isValid = rule.IsValid(dmClass);
            //---------------Test Result -----------------------
            Assert.IsTrue(isValid);
        }

        [Test]
        public void Test_IsValid_True_WhenDMClassDoesNotHaveAnAssembly()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedValidDMClass();
            dmClass.Assembly = null;
            IBusinessObjectRule rule = new DMClassNameNotEqualToAssemblyName();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(dmClass);
            Assert.IsNull(dmClass.Assembly);
            //---------------Execute Test ----------------------
            bool isValid = rule.IsValid(dmClass);
            //---------------Test Result -----------------------
            Assert.IsTrue(isValid);
        }
       
        #endregion

    }
}